package cn.yy.common.exception;

import cn.yy.common.web.Message;
import cn.yy.common.web.MessageStatus;
import cn.yy.common.web.MessageUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.SortedMap;
import java.util.TreeMap;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public Message GlobalExceptionHandle(Exception e){


        if(e instanceof CustomerException){
            CustomerException customerException = (CustomerException) e;
            if(customerException.getMessageStatus()!=null){
                return MessageUtil.error(customerException.getMessageStatus());
            }
        }
        return MessageUtil.error("后台代码错误！"+ e.getMessage());
    }
}
